var ServerNotRespond = "Server Didn't Response !";

function UserNameFocus()
{
  document.getElementById('username').focus();
}

function Validation(elementID)
{
  // UserName validation;
  var str1 = document.getElementById(elementID).value;
  var str1bool = (str1 === '' ? true : false);
  var imgelementId = elementID + '_img';

  if (str1bool)
    document.getElementById(imgelementId).style.display = 'inline';
  else
    document.getElementById(imgelementId).style.display = 'none';

  return str1bool;
}

function ControlValidation()
{
  hideErrorMsg();

  var uservalbool = Validation('username', false, 'userval');
  var pwdvalbool = Validation('password', false, 'pwdval');

  if ((uservalbool === true) || (pwdvalbool == true))
    return;
  else 
  {
    PageMethods.showLoadingPane();

    var username = document.getElementById('username').value;
    var password = document.getElementById('password').value;
    var rememberme = (document.getElementById('rememberme').checked);

    // Default timeOut 5 sn...
    PageMethods.onTimeOut = AjaxTimeout;
    PageMethods.Authenticate(username, password, rememberme);
  }
}

function AjaxTimeout()
{
  PageMethods.closeLoadingPane();

  changeErrorMsg(ServerNotRespond);
  showErrorMsg();
}

function checkoruncheck(elementID) 
{
  var element = document.getElementById(elementID);
  var value = (element.checked);

  if (value === true)
    element.checked = false;
  else if (value === false)
    element.checked = true;
}

function togglediv(divid, visible) 
{
  var div = document.getElementById(divid);
  div.style.display = visible;
}

function showErrorMsg() 
{
  togglediv('errormsg', 'inline');
}

function hideErrorMsg() {
  togglediv('errormsg', 'none');
}

function changeErrorMsg(errMsg)
{
  if (errMsg != '')
    document.getElementById('errortext').innerHTML = errMsg;
  else
    document.getElementById('errortext').innerHTML = 'Invalid UserName or Password !';
}
